<?php

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
//工作队列 轮训  只有一个队列声明 
echo '<pre>';
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
// print_r($connection);
$channel = $connection->channel();
//$channel->exchange_declare();

// print_r($channel);
// exit;

$channel->queue_declare('task_queue', false, true, false, false);

// //异步回调消息确认
// $channel->set_ack_handler(
//     function (AMQPMessage $message) {
//         echo "Message acked with content " . $message->body . PHP_EOL;
//     }
// );
// $channel->set_nack_handler(
//     function (AMQPMessage $message) {
//         echo "Message nacked with content " . $message->body . PHP_EOL;
//     }
// );
//开启消息确认
// $channel->confirm_select();


$data = "dsfsfggggg";
// $data =json_encode($data);
$msg = new AMQPMessage($data,array('delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT));


//'' 表示的是默认 交换机 即可不需要绑定一类的东西 
$channel->basic_publish($msg, '', 'task_queue');
 //阻塞等待消息确认
//  $channel->wait_for_pending_acks();

 
echo " [x] Sent \n";
$channel->close();
$connection->close();
